import { DEFAULTLAYER } from '@/libs/constant'

class BasicLine {
  constructor(props) {
    this.type = 'basicline'
    this.layer = DEFAULTLAYER
    this.startX = props?.startX || 0
    this.startY = props?.startY || 0
    this.ends = [this.startX, this.startY]
  }

  getType() {
    return this.type
  }

  getLayer() {
    return this.layer
  }

  setEnd(x, y) {
    this.ends.push(x)
    this.ends.push(y)
  }

  draw(ctx) {
    ctx.beginPath()
    ctx.moveTo(this.startX, this.startY)
    for (let index = 0; index < this.ends.length - 1; index += 2) {
      const x = this.ends[index]
      const y = this.ends[index + 1]
      ctx.lineTo(x, y)
    }
    ctx.stroke()
  }
}

export default BasicLine
